home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / picture / line.c < prev    next >
Text File  |  1993-09-23  |  2KB  |  100 lines

  1. //    Copyright 1993 Ralph Gonzalez
  2.  
  3. /*
  4. *    FILE:        line.c
  5. *    AUTHOR:        R. Gonzalez
  6. *    CREATED:    October 6, 1990
  7. *
  8. *    defines methods for 3D line segment
  9. */
  10.  
  11. # include    "line.h"
  12.  
  13. /******************************************************************
  14. *    initialize
  15. ******************************************************************/
  16. Lline::Lline(void)
  17. {
  18.     c1 = new Coord3;
  19.     c2 = new Coord3;
  20.     set_coord(10.,0.,0.,10.,0.,1.);
  21.     set_color(WHITE);
  22. }
  23.  
  24. /******************************************************************
  25. *    set coordinates
  26. ******************************************************************/
  27. void    Lline::set_coord(double x1,double y1,double z1,
  28.                 double x2,double y2,double z2)
  29. {
  30.     c1->x = x1;
  31.     c1->y = y1;
  32.     c1->z = z1;
  33.     c2->x = x2;
  34.     c2->y = y2;
  35.     c2->z = z2;
  36. }
  37.     
  38. /******************************************************************
  39. *    set color
  40. ******************************************************************/
  41. void    Lline::set_color(color line_color_val)
  42. {
  43.     line_color = line_color_val;
  44. }
  45.     
  46. /******************************************************************
  47. *    draw 3D line
  48. ******************************************************************/
  49. void    Lline::draw(Camera* camera,Projector* projector,
  50.                     Transformation* trans)
  51. {
  52.     boolean        success = TRUE;
  53.     Coord2        *image1,
  54.                 *image2;
  55.     Coord3        *new_coord;
  56.     
  57.     image1 = new Coord2;
  58.     image2 = new Coord2;
  59.     new_coord = new Coord3;
  60.     
  61.     new_coord->apply(c1,trans);
  62.     if (!camera->take_photo(image1,new_coord))
  63.         success = FALSE;
  64.     new_coord->apply(c2,trans);
  65.     if (!camera->take_photo(image2,new_coord))
  66.         success = FALSE;
  67.     if (success)
  68.         projector->show_line(image1,image2,line_color);
  69.     
  70.     delete image1;
  71.     delete image2;
  72.     delete new_coord;
  73. }
  74.  
  75. /******************************************************************
  76. *    move line coordinates
  77. ******************************************************************/
  78. void    Lline::move(Transformation* trans)
  79. {
  80.     Coord3    *temp;
  81.     
  82.     temp = new Coord3;
  83.     temp->equate(c1);
  84.     c1->apply(temp,trans);
  85.     temp->equate(c2);
  86.     c2->apply(temp,trans);
  87.     delete temp;
  88. }
  89.  
  90. /******************************************************************
  91. *    destroy
  92. ******************************************************************/
  93. Lline::~Lline(void)
  94. {
  95.     delete c1;
  96.     delete c2;
  97. }
  98.  
  99.  
  100.